﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Godot.core
{
    using SysMethodInfo = System.Reflection.MethodInfo;

    public partial class PHashTranslation : Translation
    {
        public void generate(Translation p_from) {}

        protected new bool _set(StringName p_name, Variant p_value) 
        {
	        string name = p_name;
	        if (name == "hash_table") 
            {
		        __hash_table = p_value;
		        //print_line("translation: loaded hash table of size: "+itos(hash_table.size()));
	        } else if (name=="bucket_table") {
		        __bucket_table = p_value;
		        //print_line("translation: loaded bucket table of size: "+itos(bucket_table.size()));
	        } else if (name=="strings") {
		        __strings = p_value;
		        //print_line("translation: loaded string table of size: "+itos(strings.size()));
	        } else if (name=="load_from") {
		        //print_line("generating");
		        generate((Translation)p_value);
	        } else
		        return false;

	        return true;

        }

        protected new bool _get(StringName p_name, ref Variant r_ret)
        {
	        string name = p_name;
	        if (name == "hash_table")
		        r_ret = __hash_table;
	        else if (name == "bucket_table")
		        r_ret = __bucket_table;
	        else if (name == "strings")
		        r_ret = __strings;
	        else
		        return false;
	        return true;
        }

        protected new void _get_property_list(ref List<PropertyInfo> p_list)
        {
	        p_list.Add(new PropertyInfo(Variant.Type.INT_ARRAY, "hash_table"));
	        p_list.Add(new PropertyInfo(Variant.Type.INT_ARRAY, "bucket_table"));
	        p_list.Add(new PropertyInfo(Variant.Type.RAW_ARRAY, "strings"));
	        p_list.Add(new PropertyInfo(Variant.Type.OBJECT, "load_from", PropertyHint.PROPERTY_HINT_RESOURCE_TYPE, "Translation",(int) PropertyUsageFlags.PROPERTY_USAGE_EDITOR));
        }

        protected static new void _bind_methods()
        {
            ObjectTypeDB.bind_method(_MD("generate","from:Translation"), typeof(PHashTranslation).GetMethod("generate", Misc.BindingFlags_Greedy));
        }

        private List<int> __hash_table;
        private List<int> __bucket_table;
        private List<byte> __strings; 
    }

    public partial class PHashTranslation
    {
        #region OBJ_TYPE(PHashTranslation,Translation)
        public override string get_type() { return "PHashTranslation"; }

        public override string get_save_type() { return get_type(); } //type stored when saving

        public override StringName get_type_name() { return (StringName)get_type_static(); }

        public override bool is_type(string p_type) { return (p_type == "PHashTranslation") ? true : base.is_type(p_type); }

        protected override void _initialize_typev() { initialize_type(); }

        protected override bool _setv(StringName p_name, Variant p_property)
        {
            if (base._setv(p_name, p_property))
                return true;

            if (typeof(PHashTranslation).GetMethod("_set", Misc.BindingFlags_Greedy) != typeof(Translation).GetMethod("_set", Misc.BindingFlags_Greedy))
            {
                return _set(p_name, p_property);
            }

            return false;
        }

        protected override bool _getv(StringName p_name, ref Variant r_property)
        {
            if (typeof(PHashTranslation).GetMethod("_get", Misc.BindingFlags_Greedy) != typeof(Translation).GetMethod("_get", Misc.BindingFlags_Greedy))
            {
                if (_get(p_name, ref r_property))
                    return true;
            }

            return base._getv(p_name, ref r_property);
        }

        protected override void _get_property_listv(ref List<PropertyInfo> p_list, bool p_reversed)
        {
            if (!p_reversed)
            {
                base._get_property_listv(ref p_list, p_reversed);
            }

            p_list.Add(new PropertyInfo(Variant.Type.NIL, get_type_static(), PropertyHint.PROPERTY_HINT_NONE, "", (int)PropertyUsageFlags.PROPERTY_USAGE_CATEGORY));

            if (!_is_gpl_reversed())
                ObjectTypeDB.get_property_list("PHashTranslation", ref p_list, true);

            if (typeof(PHashTranslation).GetMethod("_get_property_list", Misc.BindingFlags_Greedy) != typeof(Translation).GetMethod("_get_property_list", Misc.BindingFlags_Greedy))
            {
                _get_property_list(ref p_list);
            }

            if (_is_gpl_reversed())
                ObjectTypeDB.get_property_list("PHashTranslation", ref p_list, true);

            if (p_reversed)
            {
                base._get_property_listv(ref p_list, p_reversed);
            }
        }

        protected override void _notificationv(int p_notification, bool p_reversed)
        {
            if (!p_reversed)
                base._notificationv(p_notification, p_reversed);

            if (typeof(PHashTranslation).GetMethod("_notification", Misc.BindingFlags_Greedy) != typeof(Translation).GetMethod("_notification", Misc.BindingFlags_Greedy))
            {
                _notification(p_notification);
            }

            if (p_reversed)
                base._notificationv(p_notification, p_reversed);
        }

        public static new string get_type_static() { return "PHashTranslation"; }

        public static new string get_parent_type_static() { return Translation.get_type_static(); }

        public static new void get_inheritance_list_static(ref List<string> r_inheritance_list)
        {
            Translation.get_inheritance_list_static(ref r_inheritance_list);
            r_inheritance_list.Add(get_type_static());
        }

        public static new string get_category_static()
        {
            string category = Translation.get_category_static();
            if (typeof(PHashTranslation).GetMethod("_get_category", Misc.BindingFlags_Greedy) != typeof(Translation).GetMethod("_get_category", Misc.BindingFlags_Greedy))
            {
                if (category != "")
                    category += "/";
                category += _get_category();
            }
            return category;
        }

        public static new string inherits_static() { return "Translation"; }

        public static new void get_valid_parents_static(ref List<string> p_parents)
        {
            if (typeof(PHashTranslation).GetMethod("_get_valid_parents_static", Misc.BindingFlags_Greedy) != typeof(Translation).GetMethod("_get_valid_parents_static", Misc.BindingFlags_Greedy))
            {
                PHashTranslation._get_valid_parents_static(ref p_parents);
            }

            Translation.get_valid_parents_static(ref p_parents);
        }

        public static new void initialize_type()
        {
            if (__initialized)
                return;
            Translation.initialize_type();
            ObjectTypeDB._add_type<PHashTranslation>();

            SysMethodInfo cls_bind = typeof(PHashTranslation).GetMethod("_bind_methods", Misc.BindingFlags_Greedy);
            SysMethodInfo par_bind = typeof(Translation).GetMethod("_bind_methods", Misc.BindingFlags_Greedy);
            if (cls_bind != par_bind)
                cls_bind.Invoke(null, null);
            __initialized = true;
        }

        private static bool __initialized = false;
        #endregion
    }
}
